from prime.factor import factor
from prime.prime import is_prime

__all__ = ["euler_totient", "mobius", "sum_of_divisors"]



def sum_of_divisors(n, exp = 1):
    result = 1
    if exp == 0:
        for _p, e in factor(n):
            result *= e + 1
    else:
        for p, e in factor(n):
            result *= (p ** ((e + 1) * exp) - 1) // (p ** k - 1)
    return result


def euler_totient(n, exp = 1):
    result = n ** exp
    for p, _e in factor(n):
        result -= result // (p ** exp)
    return result


def mobius(n):
    f = factor(n)
    if any(deg > 1 for _p, deg in f):
        return 0
    else:
        return -1 if len(f) & 1 else 1
